import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

file_path = r"D:\python charm\01\可视化\销售看板参考\销售明细_12.xlsx"
df12 = pd.read_excel(file_path)

dfkd1 = (
    df12.groupby(['快递公司'])
    .size()
    .reset_index(name='数量')
)

# 设置图表风格
plt.figure(figsize=(8, 5), facecolor='#2E4057')
ax = plt.gca()
ax.set_facecolor('#2E4057')

#反转数据顺序
dfkd1 = dfkd1.iloc[::-1]

# 绘制柱状图
bars = plt.bar(dfkd1['快递公司'], dfkd1['数量'], color='#FF6F91', width=0.5)

# 添加数据标签
for bar in bars:
    plt.text(
        bar.get_x() + bar.get_width() / 2,
        bar.get_height() + 5,
        f"{int(bar.get_height())}",
        ha='center', va='bottom', fontsize=20, color='white'
    )

# 设置标题和标签
plt.title("快递公司销量", fontsize=20, color='white', pad=20)
plt.xticks(fontsize=18, color='white')
plt.yticks([])
plt.tick_params(axis='x', which='both', length=0)

# 隐藏图表边框
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()

plt.savefig(r'D:\python charm\01\可视化\销售看板参考\图片\各快递公司销量.png')

plt.show()